package com.gm.wholesale.db.order.bean;

import com.gm.commonlib.util.jsonUtils.JsonUtils;
import com.gm.wholesale.module.custom.bean.CustomBean;
import com.gm.wholesale.module.good.bean.GoodBean;
import com.gm.wholesale.module.good.bean.GoodListBean;
import com.google.gson.reflect.TypeToken;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.List;

/**
 * 挂单里面的每个订单详情
 */
@DatabaseTable(tableName = "order")
public class DBOrderContentBean implements Serializable {
    @DatabaseField
    private long goodId;

    @DatabaseField
    private String orderId;
    @DatabaseField
    private String name;
    @DatabaseField
    private long unitId;
    @DatabaseField
    private String unitName;
    @DatabaseField
    private double price;
    @DatabaseField
    private long categoryId;
    @DatabaseField
    private String categoryName;
    @DatabaseField
    private double goodNum;
    @DatabaseField
    private String customName;
    @DatabaseField
    private long customId;
    @DatabaseField
    private String contactPhone;
    @DatabaseField
    private String contactPerson;
    @DatabaseField
    private double totalPrice;

    @DatabaseField
    private String tempId;

    @DatabaseField
    private String other1; //保存得是商品单位列表数组

    @DatabaseField
    private String other2;


    @DatabaseField
    private long other3;

    public long getGoodId() {
        return goodId;
    }

    public void setGoodId(long goodId) {
        this.goodId = goodId;
    }

    public String getTempId() {
        return tempId;
    }

    public double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public void setTempId(String tempId) {
        this.tempId = tempId;
    }

    public String getOther1() {
        return other1;
    }

    public void setOther1(String other1) {
        this.other1 = other1;
    }

    public String getOther2() {
        return other2;
    }

    public void setOther2(String other2) {
        this.other2 = other2;
    }

    public long getOther3() {
        return other3;
    }

    public void setOther3(long other3) {
        this.other3 = other3;
    }

    public String getCustomName() {
        return customName;
    }

    public void setCustomName(String customName) {
        this.customName = customName;
    }

    public long getCustomId() {
        return customId;
    }

    public void setCustomId(long customId) {
        this.customId = customId;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }

    public String getContactPerson() {
        return contactPerson;
    }

    public void setContactPerson(String contactPerson) {
        this.contactPerson = contactPerson;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getUnitId() {
        return unitId;
    }

    public void setUnitId(long unitId) {
        this.unitId = unitId;
    }

    public String getUnitName() {
        return unitName;
    }

    public void setUnitName(String unitName) {
        this.unitName = unitName;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public long getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(long categoryId) {
        this.categoryId = categoryId;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public double getGoodNum() {
        return goodNum;
    }

    public void setGoodNum(double goodNum) {
        this.goodNum = goodNum;
    }

    public GoodBean toGoodBean() {
        GoodBean goodBean = new GoodBean();
        goodBean.setGoodNum(goodNum);
        // goodBean.setCategoryId(categoryId);
        // goodBean.setCategoryName(categoryName);
        goodBean.setPrice(price);
        goodBean.setUnitId(unitId);
        goodBean.setUnitName(unitName);
        goodBean.setName(name);
        goodBean.setTempId(tempId);
        goodBean.setTotalPrice(totalPrice);
        goodBean.setId(goodId);
        //单位列表数据
        if (getOther1() != null) {
            Type type = new TypeToken<List<GoodListBean.UnitsBean>>() {
            }.getType();
            List<GoodListBean.UnitsBean> units = JsonUtils.parse(getOther1(), type);
            if (units != null) {
                goodBean.setUnits(units);
            }
        }
        return goodBean;
    }

    public CustomBean getCustomBean() {
        if (customId <= 0) {
            return null;
        }
        CustomBean customBean = new CustomBean();
        customBean.setId(customId);
        customBean.setName(customName);
        return customBean;
    }
}
